#include "sql.h"
#include <QDebug>
#include <QDir>

using namespace std;
#define BUFFSIZE 4096

CSql::CSql():IGetCat(NULL)
{
    std::string pt;
    QDir dir = QDir::temp();
    dir.cdUp();
    dir.cdUp();
    QString strDir = dir.absolutePath();



    strDir.append("/Roaming/fsapp");
    if(dir.exists(strDir))
        pt = strDir.toStdString();
    else{
        strDir = QDir::currentPath();
        pt =strDir.toStdString();
    }
    dl.setFileName("libsqlite3");
    if(dl.load())
    {
        qDebug() << "dllhook加载成功:";
        IGetCat = (IGETCAT)dl.resolve("GetCat");
        if(IGetCat){
            ISql = IGetCat(pt,"parafs.db");
            qDebug() << "IGetCat 加载成功:";
        }

        //SetKeyBoardHook open = (SetKeyBoardHook)mylib.resolve("SetKeyBoardHook");
        //if(open)
        //{
         //   qDebug() << "SetKeyBoardHook加载成功";
         //   bool flag = open((HWND)this->winId());
        //}
    }

}


std::string CSql::GetValue(std::string nValue)
{
    std::string dd;
    char buf[BUFFSIZE] ={ 0 };
    ISql->GetValue1(nValue, buf);
    dd.append(buf);
    return dd;

}
std::string CSql::GetValue(std::string nValue, std::string &rValue)
{
    std::string dd;
    char buf[BUFFSIZE] ={ 0 };
    ISql->GetValue1(nValue, buf);
    rValue.append(buf);
    dd.append(buf);
    return rValue;

}
std::string CSql::GetValue1(std::string nValue, std::string &rValue)
{
    std::string dd;
    char buf[BUFFSIZE] ={ 0 };
    ISql->GetValue1(nValue, buf);
    rValue.append(buf);
    return "";

}



bool CSql::SetValue(std::string nValue, std::string dt)
{
    ISql->SetValue(nValue, dt);
    return true;
}
CSql::~CSql()
{
    ISql->delObj();
}
void CSql::exeSql(std::string sql) {
    ISql->exeSql(sql);
}
RECORDSET CSql::RecordSet(std::string sql)
{
    RECORDSET tmp;
    tmp = ISql->RecordSet(sql);
    return tmp;
}
